
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/18/2012 15:03:47
-- Generated from EDMX file: D:\Bibliotecas\Mis Documentos\Visual Studio 2010\Projects\W\W\Models\DataAccess\DataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [W];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_EstadosRecursoRecursos]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Recursos] DROP CONSTRAINT [FK_EstadosRecursoRecursos];
GO
IF OBJECT_ID(N'[dbo].[FK_EquiposReservasEquipo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservas_ReservasEquipo] DROP CONSTRAINT [FK_EquiposReservasEquipo];
GO
IF OBJECT_ID(N'[dbo].[FK_RecursosApoyoReservasRecursos]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservas_ReservasRecursos] DROP CONSTRAINT [FK_RecursosApoyoReservasRecursos];
GO
IF OBJECT_ID(N'[dbo].[FK_EstadosReservaReservas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservas] DROP CONSTRAINT [FK_EstadosReservaReservas];
GO
IF OBJECT_ID(N'[dbo].[FK_TiposRecursoRecursos]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Recursos] DROP CONSTRAINT [FK_TiposRecursoRecursos];
GO
IF OBJECT_ID(N'[dbo].[FK_AulasEquipos]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Recursos_Equipos] DROP CONSTRAINT [FK_AulasEquipos];
GO
IF OBJECT_ID(N'[dbo].[FK_AulasCaracteristicas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Caracteristicas] DROP CONSTRAINT [FK_AulasCaracteristicas];
GO
IF OBJECT_ID(N'[dbo].[FK_AulasReservasAulas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservas_ReservasAulas] DROP CONSTRAINT [FK_AulasReservasAulas];
GO
IF OBJECT_ID(N'[dbo].[FK_AulasReservasRecursos]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservas_ReservasRecursos] DROP CONSTRAINT [FK_AulasReservasRecursos];
GO
IF OBJECT_ID(N'[dbo].[FK_RolesUsuarios_Roles]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RolesUsuarios] DROP CONSTRAINT [FK_RolesUsuarios_Roles];
GO
IF OBJECT_ID(N'[dbo].[FK_RolesUsuarios_Usuarios]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[RolesUsuarios] DROP CONSTRAINT [FK_RolesUsuarios_Usuarios];
GO
IF OBJECT_ID(N'[dbo].[FK_PrivilegiosRoles_Privilegios]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PrivilegiosRoles] DROP CONSTRAINT [FK_PrivilegiosRoles_Privilegios];
GO
IF OBJECT_ID(N'[dbo].[FK_PrivilegiosRoles_Roles]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PrivilegiosRoles] DROP CONSTRAINT [FK_PrivilegiosRoles_Roles];
GO
IF OBJECT_ID(N'[dbo].[FK_UsuariosReservas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservas] DROP CONSTRAINT [FK_UsuariosReservas];
GO
IF OBJECT_ID(N'[dbo].[FK_TiposCaracteristicasCaracteristicas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Caracteristicas] DROP CONSTRAINT [FK_TiposCaracteristicasCaracteristicas];
GO
IF OBJECT_ID(N'[dbo].[FK_Equipos_inherits_Recursos]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Recursos_Equipos] DROP CONSTRAINT [FK_Equipos_inherits_Recursos];
GO
IF OBJECT_ID(N'[dbo].[FK_ReservasEquipo_inherits_Reservas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservas_ReservasEquipo] DROP CONSTRAINT [FK_ReservasEquipo_inherits_Reservas];
GO
IF OBJECT_ID(N'[dbo].[FK_RecursosApoyo_inherits_Recursos]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Recursos_RecursosApoyo] DROP CONSTRAINT [FK_RecursosApoyo_inherits_Recursos];
GO
IF OBJECT_ID(N'[dbo].[FK_ReservasRecursos_inherits_Reservas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservas_ReservasRecursos] DROP CONSTRAINT [FK_ReservasRecursos_inherits_Reservas];
GO
IF OBJECT_ID(N'[dbo].[FK_Aulas_inherits_Recursos]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Recursos_Aulas] DROP CONSTRAINT [FK_Aulas_inherits_Recursos];
GO
IF OBJECT_ID(N'[dbo].[FK_ReservasAulas_inherits_Reservas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Reservas_ReservasAulas] DROP CONSTRAINT [FK_ReservasAulas_inherits_Reservas];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Recursos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Recursos];
GO
IF OBJECT_ID(N'[dbo].[EstadosRecurso]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EstadosRecurso];
GO
IF OBJECT_ID(N'[dbo].[Caracteristicas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Caracteristicas];
GO
IF OBJECT_ID(N'[dbo].[TiposCaracteristicas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TiposCaracteristicas];
GO
IF OBJECT_ID(N'[dbo].[Reservas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Reservas];
GO
IF OBJECT_ID(N'[dbo].[EstadosReserva]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EstadosReserva];
GO
IF OBJECT_ID(N'[dbo].[TiposRecurso]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TiposRecurso];
GO
IF OBJECT_ID(N'[dbo].[Usuarios]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Usuarios];
GO
IF OBJECT_ID(N'[dbo].[Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Roles];
GO
IF OBJECT_ID(N'[dbo].[PrivilegiosEstablecer]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PrivilegiosEstablecer];
GO
IF OBJECT_ID(N'[dbo].[Recursos_Equipos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Recursos_Equipos];
GO
IF OBJECT_ID(N'[dbo].[Reservas_ReservasEquipo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Reservas_ReservasEquipo];
GO
IF OBJECT_ID(N'[dbo].[Recursos_RecursosApoyo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Recursos_RecursosApoyo];
GO
IF OBJECT_ID(N'[dbo].[Reservas_ReservasRecursos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Reservas_ReservasRecursos];
GO
IF OBJECT_ID(N'[dbo].[Recursos_Aulas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Recursos_Aulas];
GO
IF OBJECT_ID(N'[dbo].[Reservas_ReservasAulas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Reservas_ReservasAulas];
GO
IF OBJECT_ID(N'[dbo].[RolesUsuarios]', 'U') IS NOT NULL
    DROP TABLE [dbo].[RolesUsuarios];
GO
IF OBJECT_ID(N'[dbo].[PrivilegiosRoles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PrivilegiosRoles];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Recursos'
CREATE TABLE [dbo].[Recursos] (
    [id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [EstadosRecurso_id] int  NOT NULL,
    [TiposRecurso_id] int  NOT NULL
);
GO

-- Creating table 'EstadosRecurso'
CREATE TABLE [dbo].[EstadosRecurso] (
    [id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Caracteristicas'
CREATE TABLE [dbo].[Caracteristicas] (
    [id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL,
    [Aulas_id] int  NOT NULL,
    [TiposCaracteristicas_id] int  NOT NULL
);
GO

-- Creating table 'TiposCaracteristicas'
CREATE TABLE [dbo].[TiposCaracteristicas] (
    [id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Reservas'
CREATE TABLE [dbo].[Reservas] (
    [id] int IDENTITY(1,1) NOT NULL,
    [inicio] datetime  NOT NULL,
    [fin] datetime  NOT NULL,
    [fechaReserva] nvarchar(max)  NOT NULL,
    [EstadosReserva_id] int  NOT NULL,
    [Usuarios_id] int  NOT NULL
);
GO

-- Creating table 'EstadosReserva'
CREATE TABLE [dbo].[EstadosReserva] (
    [id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'TiposRecurso'
CREATE TABLE [dbo].[TiposRecurso] (
    [id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Usuarios'
CREATE TABLE [dbo].[Usuarios] (
    [id] int IDENTITY(1,1) NOT NULL,
    [username] nvarchar(max)  NOT NULL,
    [password] nvarchar(max)  NOT NULL,
    [mail] nvarchar(max)  NOT NULL,
    [lastActivityDay] datetime  NOT NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [id] int IDENTITY(1,1) NOT NULL,
    [nombre] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'PrivilegiosEstablecer'
CREATE TABLE [dbo].[PrivilegiosEstablecer] (
    [id] int IDENTITY(1,1) NOT NULL,
    [method] nvarchar(max)  NOT NULL,
    [uri] nvarchar(max)  NOT NULL,
    [route] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Recursos_Equipos'
CREATE TABLE [dbo].[Recursos_Equipos] (
    [id] int  NOT NULL,
    [Aulas_id] int  NOT NULL
);
GO

-- Creating table 'Reservas_ReservasEquipo'
CREATE TABLE [dbo].[Reservas_ReservasEquipo] (
    [id] int  NOT NULL,
    [Equipos_id] int  NOT NULL
);
GO

-- Creating table 'Recursos_RecursosApoyo'
CREATE TABLE [dbo].[Recursos_RecursosApoyo] (
    [id] int  NOT NULL
);
GO

-- Creating table 'Reservas_ReservasRecursos'
CREATE TABLE [dbo].[Reservas_ReservasRecursos] (
    [id] int  NOT NULL,
    [RecursosApoyo_id] int  NOT NULL,
    [Aulas_id] int  NOT NULL
);
GO

-- Creating table 'Recursos_Aulas'
CREATE TABLE [dbo].[Recursos_Aulas] (
    [id] int  NOT NULL
);
GO

-- Creating table 'Reservas_ReservasAulas'
CREATE TABLE [dbo].[Reservas_ReservasAulas] (
    [id] int  NOT NULL,
    [Aulas_id] int  NOT NULL
);
GO

-- Creating table 'RolesUsuarios'
CREATE TABLE [dbo].[RolesUsuarios] (
    [Roles_id] int  NOT NULL,
    [Usuarios_id] int  NOT NULL
);
GO

-- Creating table 'PrivilegiosRoles'
CREATE TABLE [dbo].[PrivilegiosRoles] (
    [Privilegios_id] int  NOT NULL,
    [Roles_id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [id] in table 'Recursos'
ALTER TABLE [dbo].[Recursos]
ADD CONSTRAINT [PK_Recursos]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'EstadosRecurso'
ALTER TABLE [dbo].[EstadosRecurso]
ADD CONSTRAINT [PK_EstadosRecurso]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Caracteristicas'
ALTER TABLE [dbo].[Caracteristicas]
ADD CONSTRAINT [PK_Caracteristicas]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'TiposCaracteristicas'
ALTER TABLE [dbo].[TiposCaracteristicas]
ADD CONSTRAINT [PK_TiposCaracteristicas]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Reservas'
ALTER TABLE [dbo].[Reservas]
ADD CONSTRAINT [PK_Reservas]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'EstadosReserva'
ALTER TABLE [dbo].[EstadosReserva]
ADD CONSTRAINT [PK_EstadosReserva]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'TiposRecurso'
ALTER TABLE [dbo].[TiposRecurso]
ADD CONSTRAINT [PK_TiposRecurso]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Usuarios'
ALTER TABLE [dbo].[Usuarios]
ADD CONSTRAINT [PK_Usuarios]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'PrivilegiosEstablecer'
ALTER TABLE [dbo].[PrivilegiosEstablecer]
ADD CONSTRAINT [PK_PrivilegiosEstablecer]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Recursos_Equipos'
ALTER TABLE [dbo].[Recursos_Equipos]
ADD CONSTRAINT [PK_Recursos_Equipos]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Reservas_ReservasEquipo'
ALTER TABLE [dbo].[Reservas_ReservasEquipo]
ADD CONSTRAINT [PK_Reservas_ReservasEquipo]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Recursos_RecursosApoyo'
ALTER TABLE [dbo].[Recursos_RecursosApoyo]
ADD CONSTRAINT [PK_Recursos_RecursosApoyo]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Reservas_ReservasRecursos'
ALTER TABLE [dbo].[Reservas_ReservasRecursos]
ADD CONSTRAINT [PK_Reservas_ReservasRecursos]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Recursos_Aulas'
ALTER TABLE [dbo].[Recursos_Aulas]
ADD CONSTRAINT [PK_Recursos_Aulas]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [id] in table 'Reservas_ReservasAulas'
ALTER TABLE [dbo].[Reservas_ReservasAulas]
ADD CONSTRAINT [PK_Reservas_ReservasAulas]
    PRIMARY KEY CLUSTERED ([id] ASC);
GO

-- Creating primary key on [Roles_id], [Usuarios_id] in table 'RolesUsuarios'
ALTER TABLE [dbo].[RolesUsuarios]
ADD CONSTRAINT [PK_RolesUsuarios]
    PRIMARY KEY NONCLUSTERED ([Roles_id], [Usuarios_id] ASC);
GO

-- Creating primary key on [Privilegios_id], [Roles_id] in table 'PrivilegiosRoles'
ALTER TABLE [dbo].[PrivilegiosRoles]
ADD CONSTRAINT [PK_PrivilegiosRoles]
    PRIMARY KEY NONCLUSTERED ([Privilegios_id], [Roles_id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [EstadosRecurso_id] in table 'Recursos'
ALTER TABLE [dbo].[Recursos]
ADD CONSTRAINT [FK_EstadosRecursoRecursos]
    FOREIGN KEY ([EstadosRecurso_id])
    REFERENCES [dbo].[EstadosRecurso]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EstadosRecursoRecursos'
CREATE INDEX [IX_FK_EstadosRecursoRecursos]
ON [dbo].[Recursos]
    ([EstadosRecurso_id]);
GO

-- Creating foreign key on [Equipos_id] in table 'Reservas_ReservasEquipo'
ALTER TABLE [dbo].[Reservas_ReservasEquipo]
ADD CONSTRAINT [FK_EquiposReservasEquipo]
    FOREIGN KEY ([Equipos_id])
    REFERENCES [dbo].[Recursos_Equipos]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EquiposReservasEquipo'
CREATE INDEX [IX_FK_EquiposReservasEquipo]
ON [dbo].[Reservas_ReservasEquipo]
    ([Equipos_id]);
GO

-- Creating foreign key on [RecursosApoyo_id] in table 'Reservas_ReservasRecursos'
ALTER TABLE [dbo].[Reservas_ReservasRecursos]
ADD CONSTRAINT [FK_RecursosApoyoReservasRecursos]
    FOREIGN KEY ([RecursosApoyo_id])
    REFERENCES [dbo].[Recursos_RecursosApoyo]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RecursosApoyoReservasRecursos'
CREATE INDEX [IX_FK_RecursosApoyoReservasRecursos]
ON [dbo].[Reservas_ReservasRecursos]
    ([RecursosApoyo_id]);
GO

-- Creating foreign key on [EstadosReserva_id] in table 'Reservas'
ALTER TABLE [dbo].[Reservas]
ADD CONSTRAINT [FK_EstadosReservaReservas]
    FOREIGN KEY ([EstadosReserva_id])
    REFERENCES [dbo].[EstadosReserva]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EstadosReservaReservas'
CREATE INDEX [IX_FK_EstadosReservaReservas]
ON [dbo].[Reservas]
    ([EstadosReserva_id]);
GO

-- Creating foreign key on [TiposRecurso_id] in table 'Recursos'
ALTER TABLE [dbo].[Recursos]
ADD CONSTRAINT [FK_TiposRecursoRecursos]
    FOREIGN KEY ([TiposRecurso_id])
    REFERENCES [dbo].[TiposRecurso]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TiposRecursoRecursos'
CREATE INDEX [IX_FK_TiposRecursoRecursos]
ON [dbo].[Recursos]
    ([TiposRecurso_id]);
GO

-- Creating foreign key on [Aulas_id] in table 'Recursos_Equipos'
ALTER TABLE [dbo].[Recursos_Equipos]
ADD CONSTRAINT [FK_AulasEquipos]
    FOREIGN KEY ([Aulas_id])
    REFERENCES [dbo].[Recursos_Aulas]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AulasEquipos'
CREATE INDEX [IX_FK_AulasEquipos]
ON [dbo].[Recursos_Equipos]
    ([Aulas_id]);
GO

-- Creating foreign key on [Aulas_id] in table 'Caracteristicas'
ALTER TABLE [dbo].[Caracteristicas]
ADD CONSTRAINT [FK_AulasCaracteristicas]
    FOREIGN KEY ([Aulas_id])
    REFERENCES [dbo].[Recursos_Aulas]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AulasCaracteristicas'
CREATE INDEX [IX_FK_AulasCaracteristicas]
ON [dbo].[Caracteristicas]
    ([Aulas_id]);
GO

-- Creating foreign key on [Aulas_id] in table 'Reservas_ReservasAulas'
ALTER TABLE [dbo].[Reservas_ReservasAulas]
ADD CONSTRAINT [FK_AulasReservasAulas]
    FOREIGN KEY ([Aulas_id])
    REFERENCES [dbo].[Recursos_Aulas]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AulasReservasAulas'
CREATE INDEX [IX_FK_AulasReservasAulas]
ON [dbo].[Reservas_ReservasAulas]
    ([Aulas_id]);
GO

-- Creating foreign key on [Aulas_id] in table 'Reservas_ReservasRecursos'
ALTER TABLE [dbo].[Reservas_ReservasRecursos]
ADD CONSTRAINT [FK_AulasReservasRecursos]
    FOREIGN KEY ([Aulas_id])
    REFERENCES [dbo].[Recursos_Aulas]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AulasReservasRecursos'
CREATE INDEX [IX_FK_AulasReservasRecursos]
ON [dbo].[Reservas_ReservasRecursos]
    ([Aulas_id]);
GO

-- Creating foreign key on [Roles_id] in table 'RolesUsuarios'
ALTER TABLE [dbo].[RolesUsuarios]
ADD CONSTRAINT [FK_RolesUsuarios_Roles]
    FOREIGN KEY ([Roles_id])
    REFERENCES [dbo].[Roles]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Usuarios_id] in table 'RolesUsuarios'
ALTER TABLE [dbo].[RolesUsuarios]
ADD CONSTRAINT [FK_RolesUsuarios_Usuarios]
    FOREIGN KEY ([Usuarios_id])
    REFERENCES [dbo].[Usuarios]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_RolesUsuarios_Usuarios'
CREATE INDEX [IX_FK_RolesUsuarios_Usuarios]
ON [dbo].[RolesUsuarios]
    ([Usuarios_id]);
GO

-- Creating foreign key on [Privilegios_id] in table 'PrivilegiosRoles'
ALTER TABLE [dbo].[PrivilegiosRoles]
ADD CONSTRAINT [FK_PrivilegiosRoles_Privilegios]
    FOREIGN KEY ([Privilegios_id])
    REFERENCES [dbo].[PrivilegiosEstablecer]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Roles_id] in table 'PrivilegiosRoles'
ALTER TABLE [dbo].[PrivilegiosRoles]
ADD CONSTRAINT [FK_PrivilegiosRoles_Roles]
    FOREIGN KEY ([Roles_id])
    REFERENCES [dbo].[Roles]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PrivilegiosRoles_Roles'
CREATE INDEX [IX_FK_PrivilegiosRoles_Roles]
ON [dbo].[PrivilegiosRoles]
    ([Roles_id]);
GO

-- Creating foreign key on [Usuarios_id] in table 'Reservas'
ALTER TABLE [dbo].[Reservas]
ADD CONSTRAINT [FK_UsuariosReservas]
    FOREIGN KEY ([Usuarios_id])
    REFERENCES [dbo].[Usuarios]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsuariosReservas'
CREATE INDEX [IX_FK_UsuariosReservas]
ON [dbo].[Reservas]
    ([Usuarios_id]);
GO

-- Creating foreign key on [TiposCaracteristicas_id] in table 'Caracteristicas'
ALTER TABLE [dbo].[Caracteristicas]
ADD CONSTRAINT [FK_TiposCaracteristicasCaracteristicas]
    FOREIGN KEY ([TiposCaracteristicas_id])
    REFERENCES [dbo].[TiposCaracteristicas]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TiposCaracteristicasCaracteristicas'
CREATE INDEX [IX_FK_TiposCaracteristicasCaracteristicas]
ON [dbo].[Caracteristicas]
    ([TiposCaracteristicas_id]);
GO

-- Creating foreign key on [id] in table 'Recursos_Equipos'
ALTER TABLE [dbo].[Recursos_Equipos]
ADD CONSTRAINT [FK_Equipos_inherits_Recursos]
    FOREIGN KEY ([id])
    REFERENCES [dbo].[Recursos]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [id] in table 'Reservas_ReservasEquipo'
ALTER TABLE [dbo].[Reservas_ReservasEquipo]
ADD CONSTRAINT [FK_ReservasEquipo_inherits_Reservas]
    FOREIGN KEY ([id])
    REFERENCES [dbo].[Reservas]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [id] in table 'Recursos_RecursosApoyo'
ALTER TABLE [dbo].[Recursos_RecursosApoyo]
ADD CONSTRAINT [FK_RecursosApoyo_inherits_Recursos]
    FOREIGN KEY ([id])
    REFERENCES [dbo].[Recursos]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [id] in table 'Reservas_ReservasRecursos'
ALTER TABLE [dbo].[Reservas_ReservasRecursos]
ADD CONSTRAINT [FK_ReservasRecursos_inherits_Reservas]
    FOREIGN KEY ([id])
    REFERENCES [dbo].[Reservas]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [id] in table 'Recursos_Aulas'
ALTER TABLE [dbo].[Recursos_Aulas]
ADD CONSTRAINT [FK_Aulas_inherits_Recursos]
    FOREIGN KEY ([id])
    REFERENCES [dbo].[Recursos]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [id] in table 'Reservas_ReservasAulas'
ALTER TABLE [dbo].[Reservas_ReservasAulas]
ADD CONSTRAINT [FK_ReservasAulas_inherits_Reservas]
    FOREIGN KEY ([id])
    REFERENCES [dbo].[Reservas]
        ([id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------